package ustc.xiaoyang.lingchashan.doublepointer;

import java.util.Arrays;

/**
 * 167.两数之和II medium
 */
public class TwoSum167
{
    public static void main(String[] args) {
        System.out.println(Arrays.toString(twoSum(new int[]{2, 7, 11, 15}, 9)));
    }

    public static int[] twoSum(int[] numbers, int target) {
        int l = 0;
        int r = numbers.length-1;
        while(l<r){
            int sum = numbers[l] + numbers[r];
            if(sum == target){
                return new int[]{l + 1,r + 1};
            }else if(sum > target){
                r--;
            }else{
                l++;
            }
        }
        return null;
    }
}
